<?php
  /**
   * iJOnlineBlock
   *
   * The iJOnlineBlock class :description
   *
   * @copyright Copyright (c) 2011, XBloks Progect
   */
    class OnlineBlock extends iJBlock{
        
        /**
         *
         * Class Constructuctor
         * @access public
         */
        public function __construct() {
    
        }
        
        
        /**
         * execute
         *
         * Executes the block to generate the tokens
         *
         * @return array Array with the tokens of the block
         *
         * @access public
         */
        public function execute() {
          $iJSession  = iJFactory::singleton('iJSession');   
          
          if(isset($_GET['Dsid'])) {
            $error = $iJSession->destroy($_GET['Dsid']);
            if(!$error) {
              iJMessages::display('success', 'session_deleted');
            } else {
              iJMessages::display('fail', 'database_error');
            }
          }
          if(isset($_GET['sid'])) {     
            $session = $iJSession->getSessionById($_GET['sid']);  
            $sessionInfo  = '';
            $sessionInfo = print_r($session, true);
            $sessionInfo = str_replace('"', '', $sessionInfo);
            $sessionInfo = trim($sessionInfo);
            $sessionInfo = htmlspecialchars($sessionInfo);
           /* echo '<pre>' . $sessionInfo .  '</pre>'; die();*/
            $this->addToken('sessionInfo',      $sessionInfo);                   
          } else {
            $iJSession = iJFactory::singleton('iJSession');
            $page   = isset($_REQUEST['page'])                                  ? $_REQUEST['page']   : 1;
            $search = isset($_REQUEST['search']) && !empty($_REQUEST['search']) ? $_REQUEST['search'] : '';
          
            $onlineList  = $iJSession->getOnlineList($page, $search);
            $online      = $onlineList[0];
            $QSession    = $onlineList[1];
          
            $this->addToken('online',      $online);         
            $this->addToken('search',      $search);
            $this->addToken('page',        $page);
          
            $this->addToken('user_icon',   iJHrefLink::Icon('user',        '16x16'));
            $this->addToken('info_icon',   iJHrefLink::Icon('info',        '16x16'));
            $this->addToken('delete_icon', iJHrefLink::Icon('user_delete', '16x16'));
          
            $this->addToken('form_action', iJHrefLink::linkToLocalPage('admin_online'));   
          
            $this->addToken('total_items',    $QSession->getSize());
            $this->addToken('pages_count',    $QSession->getPagesCount());
            $this->addToken('prev_link',      $QSession->getPerviousLink($page, 'admin_online'));
            $this->addToken('next_link',      $QSession->getNextLink($page,     'admin_online'));                      
          }
            return parent::execute();
        }
        
    }
?>